import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';

interface Message {
	filter: {
		question_bank_type: string,
		topic_type: string,
		topic: string,
		pn: number
	};
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const query = complex_query(action_id,session_id, systemid);
	const res = await query
		// 添加字段
		.add_field('question_bank', 'question_no', 'question_no')
		.add_field('question_bank', 'topic', 'topic')
		.add_field('question_bank', 'topic_type', 'topic_type')
		.add_field('question_bank', 'question_bank_type', 'question_bank_type')
		.where_like('question_bank', 'topic', "%" + message.filter.topic + "%")
		.where_like('question_bank', 'topic_type', "%" + message.filter.topic_type + "%")
		.where_like('question_bank', 'question_bank_type', "%" + message.filter.question_bank_type + "%")
		.page(20, message.filter.pn)
		.exec();
		return res;
}
